﻿using Xenta.Entities;
using Xenta.Operations;

namespace Xenta.Utils
{
    /// <summary>
    /// Contains extension methods.
    /// </summary>
    public static partial class Extensions
    {
        #region IWorkingContext

        /// <summary>
        /// Gets the publication author entity associated withe the context.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="uow">The unit of work.</param>
        /// <returns>The entity or null.</returns>
        public static PublicationAuthorEntity PublicationAuthor(this IWorkingContext ctx, IUnitOfWork uow)
        {
            var account = ctx.Account(uow);
            if(account == null)
                return null;
            return uow.Execute(new GetPublicationAuthorByAccount
            {
                AccountID = account.EntityID
            }).Result;
        }

        #endregion
    }
}
